<!--
 * @Author: liuqiang
 * @Date: 2022-04-07 15:03:56
 * @LastEditors: liuqiang
-->
<template>
  <div class="nav">
    <div @click="expend" :class="[isCollapse ? 'noSwitch' : 'onSwitch', 'Switch']"></div>
    <el-scrollbar height="100vh">
      <el-menu
        :default-active="$route.name"
        class="el-menu-vertical-demo"
        :collapse="isCollapse"
        text-color="#fff"
        active-text-color="#ffffff"
        router
      >
        <el-menu-item
          :index="menu.to"
          v-for="(menu, index) in menuList"
          :key="index"
        >
          <div class="icon"><img :src="menu.url"/></div>
          <template #title>{{ menu.title }}</template>
        </el-menu-item>
      </el-menu>
    </el-scrollbar>
  </div>
</template>

<script>
import { computed, reactive, toRefs } from 'vue'
import { useStore } from 'vuex'
export default {
  setup () {
    const state = reactive({
      isCollapse: false
    })
    const store = useStore()
    const menuList = computed(() => store.state.menuList)

    const expend = () => {
      if (state.isCollapse) state.isCollapse = false
      else state.isCollapse = true
    }

    return {
      expend,
      menuList,
      ...toRefs(state)
    }
  }
}
</script>

<style scoped lang="scss">
  @import '../css/variables.scss';
  .el-menu {
    background: linear-gradient(to right, rgb(79, 107, 208), rgb(98, 141, 185), rgb(102, 175, 161), rgb(92, 210, 133)) rgb(182, 228, 253);
    border-bottom-right-radius: 30px;color: rgb(255, 255, 255);
  }
  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 224px;
    min-height: 100vh;
    background: linear-gradient(to right, rgb(79, 107, 208), rgb(98, 141, 185), rgb(102, 175, 161), rgb(92, 210, 133)) rgb(182, 228, 253);
    border-bottom-right-radius: 30px;color: rgb(255, 255, 255);
  }
  :deep(.el-menu-item .el-menu-tooltip__trigger) {
    padding: 0 15px;
  }
  .el-menu-item:hover {
    background:-webkit-gradient(linear, 0 0, 0 bottom, from(#344a73), to(#353334));
  }
  .el-menu-item {
    height: 46px;
    line-height: 46px;
    .icon {
      width: 24px;
      height: 24px;
      display: flex;
      margin-right: 8px;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
  .el-menu-item.is-active {
    background:-webkit-gradient(linear, 0 0, 0 bottom, from(#344a73), to(#353334));
  }
  :deep(.el-scrollbar__thumb) {
    background-color: #000;
  }
  .nav {
    position: relative;
    display: flex;
    justify-content: left;
    flex-direction: column;
    .Switch {
      position: absolute;
      top: 5px;
      z-index: 1;
      width: 30px;
      height: 30px;
      cursor: pointer;
      border: 1px solid #4b95f1;
      border-radius: 5px;
      font-size: $fontSizeMin;
      text-align: center;
      color: #0036fd;
      background-position: center;
      background-size: 100%;
    }
    .onSwitch {
      right: -29px;
      transition: all .3s;
      background-image: url('../assets/icon/onswitch.png');
    }
    .noSwitch {
      right: -29px;
      transition: all .3s;
      background-image: url('../assets/icon/noswitch.png');
    }
  }
  .scrollbar-demo-item {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 50px;
    margin: 10px;
    text-align: center;
    border-radius: 4px;
    background: var(--el-color-primary-light-9);
    color: var(--el-color-primary);
  }
  .el-slider {
    margin-top: 20px;
  }
</style>
